/** ###################################################################
**     Filename  : ParkControl.h
**     Project   : parking
**     Processor : MC9S12XS128MAL
**     Compiler  : CodeWarrior HCS12X C Compiler
**     Date/Time : 2013-3-9, 15:08
**     Contents  :
**         User source code
**
** ###################################################################*/

#ifndef __ParkControl_H
#define __ParkControl_H

/* MODULE ParkControl */

#include "Types.h"
#include "CommandSystem.h"
#include "INF.h"

typedef struct ParkProcedure_t{
	S16	mode;
	S16	direction;
	S16 distance;
	S16	speed;
	S16	trig_min;
	S16	extended;
}ParkProcedure;

#define PC_DISTANCE_SCALE	(154)	 //new 20130316

#define PC_FLAG_MEMORY_ADDR	0x100000
#define PC_PROCEDURE_MEMORY_ADDR 0x101000

#define PC_FLAG_MAGIC	55555	
#define PC_FLAG_PROCEDURE_OFFSET	0

#define PC_TRIG_INIT	0
#define PC_TRIG_WAIT_FAR	1//maybe useless
#define PC_TRIG_WAIT_NEAR	2	

#define PC_DEFAULT_STOP_SPEED	(10)
#define PC_DEFAULT_STOP_DISTANCE	(2)


extern ParkProcedure PCProcedure[CS_MAX_COMMAND + 1];
extern volatile U8 PCCurrentProc;

void PCPrepare(void);

//parking control;
void PCDrive(void);
void PCExit(void);

#define PC_TIMER_SCALE	(4)
void PCTimerIrqHandler(void);
void PCTimerFreeze(void);
void PCTimerRestore(void);

bool PCInfDetect(void);
void PCGetFlagMemory(U16 offset, U16 *flag);
void PCSetFlagMemory(U16 offset, U16 flag);
void PCStoreProcedure(void);
void PCLoadProcedure(void);
void PCPassMileStone(void);
void PCInit(void);
void PCGetRunningStatus(bool *status, bool *mode);
void PCGetStatus(S16 *seq, S16 *distance);
void PCJump(S16 seq);
void PCLoop(S16 state);

/* END ParkControl */

#endif

